#include <irafhy/utility/printer.h>
#include <fstream>
#include <ctime>

namespace irafhy
{
	void Printer::write(const std::vector<capd::interval>& timeSequence,
						const std::vector<IntervalHull>&   intervalHulls,
						const std::string&				   fileName)
	{
		if (intervalHulls.empty())
			return;
		if (!timeSequence.empty())
			assert(timeSequence.size() == intervalHulls.size());
		std::ofstream outFile;
		outFile.open(fileName, std::ios::trunc);
		std::time_t now = time(nullptr);
		std::string dt	= std::ctime(&now);
		outFile << "/** Generated by printer of IraFhy in " << dt;
		outFile << "*/" << std::endl;
		if (!timeSequence.empty())
		{
			for (std::size_t index = 0; index < timeSequence.size(); ++index)
			{
				outFile << "//==================================================" << std::endl;
				outFile << "duration :" << timeSequence[index] << std::endl;
				outFile << intervalHulls[index];
			}
		}
		else
		{
			for (const auto& intervalHull : intervalHulls)
			{
				outFile << "//==================================================" << std::endl;
				outFile << intervalHull << std::endl;
			}
		}
		outFile.close();
		std::cout << "Data has been written out to the file named " << fileName << std::endl;
	}
}